<style>
	.editTable .label {
		min-width: 60px;
		width: 60px;
	}
</style>
<form id="editForm" method="post">
	<input type="hidden" name="id" id="id">
	<table class="editTable">
		<tr>
			<td class="label">角色名</td>
			<td><input type="text" name="roleName" class="topjui-textbox"
			           data-options="required:true,validType:'length[1,30]'"
			           style="width: 351px;">
			</td>
		</tr>
		<tr>
			<td class="label">功能权限</td>
			<td>
				<div style="border: 1px solid #A4BED4; width:350px;height:210px;overflow: auto;">
					<ul id="zTree" class="ztree" style="margin: 3px;"></ul>
				</div>
				<input type="hidden" id="strFuncMenu" name="strFuncMenu" value="">
			</td>
		</tr>
		<tr>
			<td class="label">描述</td>
			<td colspan="3">  <textarea style="width: 352px;height:65px;"
			                            maxlength="250" name="remark"></textarea>
			</td>
		</tr>
	</table>
</form>

<script type="text/javascript">
	var setting = {
		check: {
			enable: true
		},
		data: {
			simpleData: {
				enable: true
			}
		}, callback: {
			onCheck: onCheck
		}
	};


	$(function () {
		$.post(path + "/funcConfig/funcConfigTree", function (data) {
			//console.info(data);
			$.fn.zTree.init($("#zTree"), setting, data);
			var treeObj = $.fn.zTree.getZTreeObj("zTree");
			var menuIds = $("#strFuncMenu").val();
			var array = new Array();
			if (menuIds != '') {
				array = menuIds.split(',');
				$.each(array, function (i, id) {
					if (id != null && id != '') {
						var node = treeObj.getNodeByParam("id", id);
						treeObj.checkNode(node, true, true);
					}
				});
			}
		});
	});


	function onCheck(e, treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("zTree"),
				nodes = zTree.getCheckedNodes(true),
				s = "";
		for (var i = 0, l = nodes.length; i < l; i++) {

			if (nodes[i].check_Child_State != 1) {  //去除半选节点
				s += nodes[i].id + ","
			}
		}
		if (s != "") {
			s = s.substring(0, s.length - 1);
		}
		$("#strFuncMenu").val(s);
		//console.info(s);
	}

</script>
